Skip to content

speedup the inference of vit (gelu, rmsnorm and fa3 for H-series) and chunked prefill for multimodal #766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Apr 2, 2025

Conversation

SangChengC
Copy link
Contributor

No description provided.

@SangChengC SangChengC force-pushed the fix_chuned_prefill branch 2 times, most recently from f5e5bbd to 9d475cb Compare March 13, 2025 05:24
@shihaobai shihaobai changed the title fix chunked prefill speedup the inference of vit (gelu, rmsnorm and fa3 for H-series) and chunked prefill for multimodal Mar 28, 2025
@shihaobai shihaobai requested a review from Copilot March 28, 2025 09:12
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR accelerates ViT inference by integrating optimized Triton kernels for gelu and rms norm operations, adds flash attention support for Hopper GPUs, and implements chunked prefill for multimodal scenarios. Key changes include:

  • Enhancements to VisualModelRpcServer and model.encode to support per-image maximum patch counts via max_num_list.
  • Updates in router, multimodal parameters, and memory cache logic to propagate and utilize a new max_num parameter.
  • Integration of Triton kernels for gelu and rms norm, along with adjustments in backend and preprocessing for multimodal inputs.

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lightllm/server/visualserver/model_infer/model_rpc.py Propagates max_num_list to model.encode in forward for multimodal inference.
lightllm/server/router/model_infer/model_rpc.py Passes is_multimodal flag to chunked prefill backend.
lightllm/server/router/model_infer/mode_backend/chunked_prefill/impl.py Updates chunked prefill to accept is_multimodal parameter.
lightllm/server/multimodal_params.py Introduces max_num parameter and corresponding logic.
lightllm/server/embed_cache/*.py Adds new API for max_num and updates memory cache record structure.
lightllm/server/api_http.py Adjusts multimodal image processing and token counting.
lightllm/models/vit/* Modifies encode and layer inference functions to support new gelu/rms norm kernels.
lightllm/models/internvl/* Updates image token length calculations and preprocessing to include max_num.
Comments suppressed due to low confidence (2)

lightllm/server/embed_cache/utils.py:16

  • [nitpick] The parameter name 'img_str' is ambiguous because it may represent either a file path or a file-like stream. Consider renaming it to something that clearly indicates the expected input type, like 'image_input'.
def image2base64(img_str: str):

lightllm/server/api_http.py:251

  • Passing 'response.raw' (a stream) to image2base64 assumes that the function can handle file-like objects. Verify and document the accepted input types for image2base64 or adjust its implementation accordingly.
data = image2base64(response.raw)

if self.tp_rank_id == 0:
for i in range(len(images_uuids)):
uid = images_uuids[i]
max_num_list.append(self.cache_client.root.get_max_num(uid))
Copy link
Preview

Copilot AI Mar 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, max_num_list is populated only when self.tp_rank_id == 0, which may result in an empty list for other ranks. Consider ensuring a consistent max_num_list is provided to self.model.encode for all cases.

Suggested change
max_num_list.append(self.cache_client.root.get_max_num(uid))
max_num_list[i] = self.cache_client.root.get_max_num(uid)

Copilot uses AI. Check for mistakes.

@SangChengC SangChengC closed this Mar 28, 2025
@SangChengC SangChengC reopened this Mar 28, 2025
@SangChengC SangChengC closed this Mar 28, 2025
@SangChengC SangChengC reopened this Mar 28, 2025
@SangChengC SangChengC force-pushed the fix_chuned_prefill branch 3 times, most recently from 3f76f9e to 52c6b99 Compare March 31, 2025 09:55
@ModelTC ModelTC deleted a comment from Copilot AI Mar 31, 2025
@@ -21,6 +22,7 @@ def __init__(self, **kwargs):
self.image_h = 0

self._preload_data = None
self.extra_params = {"image_patch_max_num": kwargs.get("max_num", None)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

通用性。

@SangChengC SangChengC force-pushed the fix_chuned_prefill branch 4 times, most recently from edb87de to 9e3ae23 Compare April 1, 2025 10:27
@SangChengC SangChengC force-pushed the fix_chuned_prefill branch from 9e3ae23 to 01b3f68 Compare April 2, 2025 03:26
@SangChengC SangChengC force-pushed the fix_chuned_prefill branch 3 times, most recently from cb7fd6d to 1f25c14 Compare April 2, 2025 04:58
@SangChengC SangChengC force-pushed the fix_chuned_prefill branch from 1f25c14 to ea0fe0d Compare April 2, 2025 05:00
@hiworldwzj hiworldwzj merged commit 750957f into main Apr 2, 2025
1 check passed
@shihaobai shihaobai deleted the fix_chuned_prefill branch May 29, 2025 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants